package com.bpc.cs.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.bpc.cs.dao.IFactorChoiceDAO;
import com.bpc.cs.dao.IRuleDAO;
import com.bpc.cs.dto.FactorChoiceDTO;
import com.bpc.cs.managed.dvo.FactorChoiceDVO;
import com.bpc.cs.managed.dvo.RuleDVO;
import com.bpc.cs.util.Util;

/**
 * @author   phan_tp
 * @datetime Nov 30, 2012 : 4:45:57 PM
 */

@Transactional(readOnly = false)
public class FactorChoiceService implements IFactorChoiceService {

	private IFactorChoiceDAO factorChoiceDAO;
	private IRuleDAO ruleDAO;

	/**
	 * Get list factor choice by RuleID
	 * @param int ruleID
	 * @return List<FactorChoiceDVO>
	 */
	@Override
	public List<FactorChoiceDVO> getFactorChoiceByRuleID(int ruleID) {
		return Util.cvnFactorChoiceDTO2DVO(ruleDAO.selectFactorChoiceByRuleID(ruleID));
	}

	/**
	 * Add new factor choice
	 * @param int ruleID
	 * @param String factor choice
	 * @param int score
	 * @return Boolean TRUE : add successful
	 * 				   FALSE: add failed
	 */
	@Override
	public boolean addFactorChoice(RuleDVO ruleDVO, String factorChoice, int score) {
		FactorChoiceDTO factorChoiceDTO  = new FactorChoiceDTO();
		factorChoiceDTO.setRuleDTO(Util.cvnRuleDVO2DTO(ruleDVO));
		factorChoiceDTO.setFactorChoice(factorChoice);
		factorChoiceDTO.setScore(score);
		return factorChoiceDAO.insertFactorChoice(factorChoiceDTO);
	}

	/**
	 * Remove factorChoice
	 * @param int factorChoiceID
	 * @return boolean TRUE : remove successfully
	 * 				   FALSE: remove failed
	 */
	@Override
	public boolean removeFactorChoice(int factorChoiceID) {
		return factorChoiceDAO.deleteFactorChoice(factorChoiceID);
	}

	/**
	 * @return the factorDAO
	 */
	public IFactorChoiceDAO getFactorChoiceDAO() {
		return factorChoiceDAO;
	}

	/**
	 * @param factorChoiceDAO the factorDAO to set
	 */
	public void setFactorChoiceDAO(IFactorChoiceDAO factorChoiceDAO) {
		this.factorChoiceDAO = factorChoiceDAO;
	}

	/**
	 * @return the ruleDAO
	 */
	public IRuleDAO getRuleDAO() {
		return ruleDAO;
	}

	/**
	 * @param ruleDAO the ruleDAO to set
	 */
	public void setRuleDAO(IRuleDAO ruleDAO) {
		this.ruleDAO = ruleDAO;
	}

}
